package com.example.rockpaperscissors;

import java.util.Random;

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction()
					.add(R.id.container, new PlaceholderFragment()).commit();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {
		
		ImageView datRock;
		ImageView datPaper;
		ImageView datScissors;
		ImageView datNewRound;
		TextView datScore;
		TextView datAnnouncement;
		
		int datChoice;
		Integer datInternalScore = 0;

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main, container,
					false);
			
			datRock = (ImageView)rootView.findViewById(R.id.DatRock);
			datPaper = (ImageView)rootView.findViewById(R.id.DatPaper);
			datScissors = (ImageView)rootView.findViewById(R.id.DatScissors);
			datNewRound = (ImageView)rootView.findViewById(R.id.DatNewRound);
			datScore = (TextView)rootView.findViewById(R.id.DatScore);
			datAnnouncement = (TextView)rootView.findViewById(R.id.DatAnnouncement);
			
			datRock.setOnClickListener(new OnClickListener() {

				
				public void onClick(View arg0) {
					
					datChoice = 1;
					
					Random datRndm= new Random();
					
					int datNPC = datRndm.nextInt(3);
					datNPC = datNPC + 1;
					
					///// 1 IS A ROCK
					////  2 IS A PAPER
					////  3 IS SCISSORS
					
					
					/////THE WINNING CONDITIONS//////
					if (datChoice == 1 && datNPC == 3)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: SKIZRS!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 2 && datNPC == 1)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: UURRRCK!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 3 && datNPC == 2)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: PAYYYPURR!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					
							///// 1 IS A ROCK
							////  2 IS A PAPER
							////  3 IS SCISSORS
					
					/////THE LOSING CONDITIONS/////
					
					else if (datChoice == 1 && datNPC == 2)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: PAYYYPURR!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 2 && datNPC == 3)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: SKIZRS!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 3 && datNPC == 1)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: UURRRCK!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					/////DAT TIE THO///////
					else
					{
						////   NIHILISM!!!!!
					}
					// TODO Auto-generated method stub
					
				}
			});
			
			datPaper.setOnClickListener(new OnClickListener() {

				
				public void onClick(View arg0) {
					
					datChoice = 2;
					
					Random datRndm= new Random();
					
					int datNPC = datRndm.nextInt(3);
					datNPC = datNPC + 1;
					
					///// 1 IS A ROCK
					////  2 IS A PAPER
					////  3 IS SCISSORS
					
					
					/////THE WINNING CONDITIONS//////
					if (datChoice == 1 && datNPC == 3)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: SKIZRS!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 2 && datNPC == 1)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: UURRRCK!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 3 && datNPC == 2)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: PAYYYPURR!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					
							///// 1 IS A ROCK
							////  2 IS A PAPER
							////  3 IS SCISSORS
					
					/////THE LOSING CONDITIONS/////
					
					else if (datChoice == 1 && datNPC == 2)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: PAYYYPURR!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 2 && datNPC == 3)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: SKIZRS!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 3 && datNPC == 1)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: UURRRCK!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					/////DAT TIE THO///////
					else
					{
						////   NIHILISM!!!!!
					}
					// TODO Auto-generated method stub
					
				}
			});
			
			datScissors.setOnClickListener(new OnClickListener() {

				
				public void onClick(View arg0) {
					
					datChoice = 3;
					
					Random datRndm= new Random();
					
					int datNPC = datRndm.nextInt(3);
					datNPC = datNPC + 1;
					
					///// 1 IS A ROCK
					////  2 IS A PAPER
					////  3 IS SCISSORS
					
					
					/////THE WINNING CONDITIONS//////
					if (datChoice == 1 && datNPC == 3)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: SKIZRS!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 2 && datNPC == 1)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: UURRRCK!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 3 && datNPC == 2)
					{
						datInternalScore++;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: PAYYYPURR!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					
							///// 1 IS A ROCK
							////  2 IS A PAPER
							////  3 IS SCISSORS
					
					/////THE LOSING CONDITIONS/////
					
					else if (datChoice == 1 && datNPC == 2)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: PAYYYPURR!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 2 && datNPC == 3)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: SKIZRS!!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					else if (datChoice == 3 && datNPC == 1)
					{
						datInternalScore--;
						String datStringtho = "Score: " + datInternalScore.toString();
						datScore.setText(datStringtho);
						
						String dat2Stringtho = "Android chose: UURRRCK!";
						datAnnouncement.setText(dat2Stringtho);
					}
					
					/////DAT TIE THO///////
					else
					{
						////   NIHILISM!!!!!
					}
					// TODO Auto-generated method stub
					
				}
			});
			
			
			
				datNewRound.setOnClickListener(new OnClickListener() {

				
				public void onClick(View arg0) {
					
					String dat2Stringtho = "Android chose: Nothing Yet!";
					datAnnouncement.setText(dat2Stringtho);
					// TODO Auto-generated method stub
					
				}
				
				
			});
			
				
			
			
			return rootView;
		}
	}

}
